package com.refusea.train.mapper

import com.refusea.train.domain.entity.Referrer
import org.apache.ibatis.annotations.Delete
import org.apache.ibatis.annotations.Insert
import org.apache.ibatis.annotations.Mapper
import org.apache.ibatis.annotations.Param
import org.apache.ibatis.annotations.Select
import org.apache.ibatis.annotations.Update
import java.time.LocalDate

/**
 * @author Zhang Yan 2024/4/23
 **/
@Mapper
interface ReferrerMapper {

    @Select("SELECT * FROM referrer WHERE school_id = #{schoolId}")
    fun list(schoolId: Int): List<Referrer>

    @Insert(
        """
        INSERT INTO referrer (school_id, name, signup_commission, order_commission) 
        VALUES (#{schoolId}, #{name}, #{signupCommission}, #{orderCommission})
        """
    )
    fun insert(referrer: Referrer): Int

    @Update(
        """
        UPDATE referrer SET signup_commission = #{signupCommission}, order_commission = #{orderCommission} 
        WHERE id = #{id} and school_id = #{schoolId}
        """
    )
    fun update(referrer: Referrer): Int

    @Select("SELECT * FROM referrer")
    fun listAll(): List<Referrer>

    @Delete("DELETE FROM referrer WHERE id = #{id} and school_id = #{schoolId}")
    fun delete(@Param("schoolId") schoolId: Int, @Param("id") id: Int)
}
